/*!
 *@file BaseTabBar.qml
 *@brief 自定义TabBar
 *@version 1.0

*/
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

TabBar {
    property alias myModel: myModel
    property int lastIndex: 0

    id: bar
    currentIndex: 0
    onCurrentIndexChanged: {
        repeater.itemAt(currentIndex).clicked()
    }
    spacing: 0
    ListModel {
        id: myModel
    }

    Repeater {
        id: repeater
        model: myModel

        TabButton {
            id: myTabBtn
            property alias imageSource: myTabBtn.icon.source
            property alias backColor: backRec.color
            property alias textColor: myText.color

            //height: bar.height
            height: 64
            contentItem:Text{
                id: myText
                text: modelText
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignBottom
                color: (model.index === bar.currentIndex) ? modelColor : modelColorG
            }
            background: Rectangle {
                id: backRec
                implicitWidth: 100
                implicitHeight: 64
                color:  (model.index === bar.currentIndex) ? "green" : "white"
                border.width: 1
                border.color: "#ddd"
                Image{
                    width: 36
                    height: 36
                    anchors.horizontalCenter: parent.horizontalCenter
                    source: (model.index === bar.currentIndex) ? modelSrcG : modelSrc
                }

            }

            //icon.source:
            onClicked: {
                repeater.itemAt(bar.lastIndex).imageSource = myModel.get(bar.lastIndex).modelSrc;
                repeater.itemAt(bar.lastIndex).backColor = "white"
                repeater.itemAt(bar.lastIndex).textColor = modelColorG;

                imageSource = modelSrcG;
                backColor = "green"
                text.color = modelColor;
                bar.lastIndex = model.index;
            }
        }
    }
}
